﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using SIGERP_Entidades;
using SIGERP_Negocio;
using System.Data.SqlClient;

namespace SIGERP_Presentacion
{
    public partial class frmTipoReclamo : Form
    {
        List<TipoReclamo> tiposreclamos;
        DataTable dt;

        public frmTipoReclamo()
        {
            InitializeComponent();
            CargarGrilla();
        }

        private void CargarGrilla()
        {
            dt = new DataTable();
            dt.Columns.Add("Id", typeof(int));
            dt.Columns.Add("Tipo Reclamo", typeof(String));

            tiposreclamos = TiposReclamo.GetAll();
            foreach (TipoReclamo tr in tiposreclamos)
                dt.Rows.Add(tr.ID, tr.DescTipoReclamo);
            Grilla.DataSource = dt;

            Grilla.Columns[0].Visible = false;

        }

        private void Grilla_DoubleClick(object sender, EventArgs e)
        {
            editarTipoReclamo();
        }


        private void frmPais_Load(object sender, EventArgs e)
        {
            CargarGrilla();
        }

        private void picTitulo_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {

        }

        private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void toolStripStatusLabel1_Click(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void label1_Click_1(object sender, EventArgs e)
        {

        }

        private void mnuSalir_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnBuscar_Click(object sender, EventArgs e)
        {

        }

        private void btnAgregar_Click(object sender, EventArgs e)
        {
            frmTipoReclamoAgregar frm = new frmTipoReclamoAgregar();
            if (frm.ShowDialog() == DialogResult.OK) CargarGrilla();
            frm.Dispose();
            CargarGrilla();
        }

        private void Grilla_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            editarTipoReclamo();
        }

        private void editarTipoReclamo()
        {
            if (Grilla.SelectedRows.Count == 1)
            {
                TipoReclamo tr = new TipoReclamo();
                tr.ID = Convert.ToInt32(Grilla.SelectedRows[0].Cells["Id"].Value);
                tr.DescTipoReclamo = Grilla.SelectedRows[0].Cells["Tipo Reclamo"].Value.ToString();
                frmTipoReclamoActualizar frm = new frmTipoReclamoActualizar(tr);
                if (frm.ShowDialog() == DialogResult.OK) CargarGrilla();
                frm.Dispose();
                CargarGrilla();
            }
        }

        private void mnuEliminar_Click(object sender, EventArgs e)
        {
            if (Grilla.SelectedRows.Count == 1)
            {
                if (MessageBox.Show("¿Desea dar de baja el registro seleccionado?", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    TipoReclamo tr = new TipoReclamo();
                    tr.ID = Convert.ToInt32(Grilla.SelectedRows[0].Cells["Id"].Value);
                    tr.DescTipoReclamo = Grilla.SelectedRows[0].Cells["Tipo Reclamo"].Value.ToString();
                    TiposReclamo.Baja(tr);
                    CargarGrilla();
                }
            }
        }

        private void btnEditar_Click(object sender, EventArgs e)
        {
                editarTipoReclamo();
        }

        private void txtPais_TextChanged(object sender, EventArgs e)
        {
            busqueda();
        }

        private void busqueda()
        {
            dt.Clear();

            foreach (TipoReclamo tr in tiposreclamos)
            {

                if (tr.DescTipoReclamo.ToUpper().StartsWith(txtTipoReclamo.Text.ToUpper()))
                    dt.Rows.Add(tr.ID, tr.DescTipoReclamo);
            }
        }
    }
}